package com.jsmtr.rms.controller.DUserResume;

import com.jsmtr.rms.entity.*;
import com.jsmtr.rms.service.IDoResumeService;
import com.jsmtr.rms.utils.WordHelper.WordByFreeMarker;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: cyx
 * @description:
 * @date: Created in 2020-2-24 21:09
 * @modified by:
 */
@Controller
public class DUserResumeOutputController {
    @Resource
    private IDoResumeService doResumeService;

    @RequestMapping(value = "/DUserResume/OutputByWordAction", method = RequestMethod.POST)
    public void OutputByWord(HttpServletRequest request, HttpServletResponse response){
        try {
            String[] ids = request.getParameterValues("id");//人员信息ID
            if (ids != null) {
                for (String id : ids) {
                 DUserResume dUserResume= doResumeService.getDUserResume(id);
                 Map resumeMap=new HashMap<>();
                    resumeMap.put("name",dUserResume.getName());
                    resumeMap.put("sexname",dUserResume.getSexname());
                    resumeMap.put("birthday",dUserResume.getBirthday());
                    resumeMap.put("email",dUserResume.getEmail());
                    resumeMap.put("head",dUserResume.getHead());
                    resumeMap.put("tel",dUserResume.getTel());
                    resumeMap.put("hometel",dUserResume.getHometel());
                    resumeMap.put("mzname",dUserResume.getMzname());
                    resumeMap.put("jg",dUserResume.getJg());
                    resumeMap.put("zzmmname",dUserResume.getZzmmname());
                    resumeMap.put("height",dUserResume.getHeight());
                    resumeMap.put("mname",dUserResume.getMname());
                    resumeMap.put("distribution",dUserResume.getDistribution());
                    resumeMap.put("cardno",dUserResume.getCardno());
                    resumeMap.put("jname",dUserResume.getJname());
                    resumeMap.put("hkname",dUserResume.getHkname());
                    resumeMap.put("hukouaddress",dUserResume.getHukouaddress());
                    resumeMap.put("nowaddress",dUserResume.getNowaddress());
                    resumeMap.put("workexperience",dUserResume.getWorkexperience());
                    resumeMap.put("attendancetime",dUserResume.getAttendancetime());
                    resumeMap.put("presentsalaryamount",dUserResume.getPresentsalaryamount());
                    resumeMap.put("expectedsalaryamount",dUserResume.getExpectedsalaryamount());
                    resumeMap.put("posttypename",dUserResume.getPosttypename());
                    resumeMap.put("postspecialty",dUserResume.getPostspecialty());
                    resumeMap.put("postlevelname",dUserResume.getPostlevelname());
                    resumeMap.put("postgettime",dUserResume.getPostgettime());
                    resumeMap.put("postcompany",dUserResume.getPostcompany());
                    resumeMap.put("qltype",dUserResume.getQltype());
                    resumeMap.put("qllevelpname",dUserResume.getQllevelpname());
                    resumeMap.put("qllevelname",dUserResume.getQllevelname());
                    resumeMap.put("qllevelsname",dUserResume.getQllevelsname());
                    resumeMap.put("qlgettime",dUserResume.getQlgettime());
                    resumeMap.put("qlorg",dUserResume.getQlorg());
                    resumeMap.put("othname",dUserResume.getOthname());
                    resumeMap.put("othtypename",dUserResume.getOthtypename());
                    resumeMap.put("othzy",dUserResume.getOthzy());
                    resumeMap.put("othlevel",dUserResume.getOthlevel());
                    resumeMap.put("othcode",dUserResume.getOthcode());
                    resumeMap.put("othorg",dUserResume.getOthorg());

                    String rid = dUserResume.getId();
                    List<DUserEducation> educations = doResumeService.getUserEducation(rid);//教育背景
                    resumeMap.put("edulist",educations);
                    List<DUserWorkExperience> workexperiences = doResumeService.getUserWorkExperience(rid); //工作经验
                    resumeMap.put("worklist",workexperiences);
                    List<DUserTraining> trainings = doResumeService.getUserTraining(rid); //培训经历
                    resumeMap.put("trainlist",trainings);
                    List<DUserRewardPunishment> rewardpunishments = doResumeService.getUserRewardPunishment(rid); //获奖信息
                    resumeMap.put("punishmentlist",rewardpunishments);
                    List<DUserFamily> families = doResumeService.getUserFamily(rid);//家庭成员
                    resumeMap.put("familylist",families);
                    WordByFreeMarker word = new WordByFreeMarker();
                    String tempName="DUserResume.ftl";
                    System.out.println(tempName);
                    word.createWord(resumeMap,tempName,request.getServletContext().getRealPath("upload/"+dUserResume.getProname()+"/"+dUserResume.getCardno()+dUserResume.getName()+".doc"));
                }
            }
        }catch (Exception e){

        }
    }
}
